﻿using System;
using System.Collections.Generic;
using Games;

namespace Jinhua
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("炸金花游戏开始!");
            Console.WriteLine();

            if (args.Length < 1)
            {
                Console.WriteLine("请至少输入一名玩家!");
            }
            else if (args.Length > 15)
            {
                Console.WriteLine("最多只能有 14 名玩家, 因为扑克牌不够用!");
            }
            else
            {
                IGame game = new JiahuaGame()
                {
                    Rule = new GameRule(),
                    Players = new List<Player>()
                };

                var seatIndex = 1;
                var players = args[0..^1];
                foreach (var player in players)
                {
                    game.Players.Add(new Player(player, seatIndex++));
                }

                var playCount = 1;
                try
                {
                    playCount = Convert.ToInt32(args[^1]);
                }
                catch (Exception)
                {
                    Console.WriteLine($"最后一个输入参数 {args[^1]} 作为游戏次数不正确, 游戏将只进行一局!");
                }

                for (int index = 0; index < playCount; index++)
                {
                    game.Play();
                }

                game.Over();
            }

            Console.WriteLine("按回车键退出!");
            Console.ReadLine();
        }
    }
}
